/**
 * @ProjectName: ShopSytem
 * @Title: GetGoodList.java 
 * @Package com.element5th.shop.servlet.good 
 * @Description: 按照查找条件找到符合的商品列表
 * @author 第五元素小组   
 * @date 2012-10-26 16:41:49 
 * @version V1.0   
 */
package com.element5th.shop.servlet.good;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.element5th.comm.ServletUtil;
import com.element5th.shop.dao.good.GoodDaoImpl;
import com.element5th.shop.dao.good.IGoodDao;
import com.element5th.shop.dto.BaseDto;
import com.element5th.shop.dto.GoodFindDto;

/**
 * Servlet implementation class ViewGoodList
 */
@WebServlet("/page/good_list")
public class GetGoodList extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Integer classId = ServletUtil.getInteger(request, "classId");
		String className = request.getParameter("className");
		String bigClassName = request.getParameter("bigClassName");
		String path = "/page/shop/ListPage.jsp";

		BaseDto goodDto = new BaseDto();
		List<BaseDto> classDtoList = new ArrayList<BaseDto>();
		List<BaseDto> goodDtoList = new ArrayList<BaseDto>();
		GoodFindDto findDto = new GoodFindDto();
		IGoodDao dao = new GoodDaoImpl();
		findDto.setClassId(classId);
		goodDto.getGoodBigClass().setBigclassName(bigClassName);

		classDtoList = dao.GetClassListByBigClassId(goodDto);
		goodDtoList = dao.getGoodListByClass(findDto);
		
		int count = goodDtoList.size();

		request.setAttribute("classDtoList", classDtoList);
		request.setAttribute("goodDtoList", goodDtoList);
		request.setAttribute("count", count);
		request.setAttribute("className", className);
		request.setAttribute("bigClassName", bigClassName);

		this.getServletContext().getRequestDispatcher(path)
				.forward(request, response);
	}

}
